/*
 * Copyright 2009 Michal Trzcinka
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
function confirm(url, method) {
  var dialog = new YAHOO.widget.SimpleDialog("dlg", {
    width: "20em",
    fixedcenter:true,
    modal:true,
    visible:false,
    draggable:false });
  dialog.setHeader("Confirm");
  dialog.setBody("Are you sure?");
  dialog.cfg.setProperty("icon", YAHOO.widget.SimpleDialog.ICON_WARN);
  var handleYes = function() {
    var f = document.createElement('form');
    f.style.display = 'none';
    dialog.body.parentNode.appendChild(f);
    f.method = 'POST';
    f.action = url;
    if (method != 'post') {
      var m = document.createElement('input');
      m.setAttribute('type', 'hidden');
      m.setAttribute('name', '_method');
      m.setAttribute('value', method);
      f.appendChild(m);
    }
    f.submit();

    this.hide();
  };
  var handleNo = function() {
    this.hide();
  };
  var myButtons = [ { text:"Yes",
    handler:handleYes },
    { text:"No",
      handler:handleNo,
      isDefault:true } ];
  dialog.cfg.queueProperty("buttons", myButtons);

  dialog.render(document.body);
  dialog.show();
}